pipenv install asana
import asana
from asana.rest import ApiException
from pprint import pprint
# Configure OAuth2 access token for authorization: oauth2
configuration = asana.Configuration()
configuration.access_token = '<YOUR_PERSONAL_ACCESS_TOKEN>'
api_client = asana.ApiClient(configuration)
# create an instance of the API class
api_instance = asana.WorkspacesApi(api_client)
limit = 50 # int | Results per page. The number of objects to return per page. The value must be between 1 and 100. (optional)
offset = 'eyJ0eXAiOJiKV1iQLCJhbGciOiJIUzI1NiJ9' # str | Offset token. An offset to the next page returned by the API. A pagination request will return an offset token, which can be used as an input parameter to the next request. If an offset is not passed in, the API will return the first page of results. 'Note: You can only pass in an offset that was returned to you via a previously paginated request.' (optional)
opt_fields = ["email_domains","is_organization","name","offset","path","uri"] # list[str] | This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include. (optional)
try:
# Get multiple workspaces
api_response = api_instance.get_workspaces(limit=limit, offset=offset, opt_fields=opt_fields)
pprint(api_response)
except ApiException as e:
print("Exception when calling WorkspacesApi->get_workspaces: %s\n" % e)
import asana
import configparser
from asana.rest import ApiException
def get_workspaces():
# Configure OAuth2 access token for authorization: oauth2
configuration = asana.Configuration()
config = configparser.ConfigParser()
config.read('config.ini')
configuration.access_token = config['Asana']['asana_token']
api_client = asana.ApiClient(configuration)
# create an instance of the API class
api_instance = asana.WorkspacesApi(api_client)
try:
# Get multiple workspaces
api_response = api_instance.get_workspaces()
return api_response
except ApiException as e:
print("Exception when calling WorkspacesApi->get_workspaces: %s\n" % e)
configuration.access_token = '<YOUR_PERSONAL_ACCESS_TOKEN>'
被我換成 configuration.access_token = config['Asana']['asana_token']
>>> worksp = get_workspaces()
>>> type(worksp)
<class 'asana.models.workspace_response_array.WorkspaceResponseArray'>
>>>
WorkspaceResponseArray
並不是常見可以直接拿來用的資料型別dir()
拆開來玩,而我選擇懶得看文件的做法to_dict()
可以用
>>> worksp.to_dict()
{'data': [{'gid': '1xxxxxxxxxxxxxx8', 'resource_type': 'workspace', 'name': 'xxx.com', 'email_domains': None, 'is_organization': None}], 'next_page': None}
gid
,啊我程式擺著產出自己投影片,gid
又不會變gid
、以後也不會加入新的 Asana Workspace、程式也不會拿給別人用的話,真的都無所謂超強的材料研發組
和 負責訂便當的庶務組
還有 總經理室
之類的東西